package top.market.model.entity;

/**
 * @Description:
 * @Author: liyuhai
 * @Date: 2025/3/28
 */
public enum OrderStatusEnum {
    PENDING_PAYMENT(1, "待付款"),
    PENDING_CONFIRMATION(2, "待接单"),
    CONFIRMED(3, "已接单"),
    DELIVERING(4, "派送中"),
    COMPLETED(5, "已完成"),
    CANCELLED(6, "已取消"),
    REFUNDED(7, "退款");

    private final Integer code;
    private final String description;

    OrderStatusEnum(int code, String description) {
        this.code = code;
        this.description = description;
    }

    public int getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    // 根据代码获取枚举值
    public static OrderStatusEnum fromCode(int code) {
        for (OrderStatusEnum status : values()) {
            if (status.code == code) {
                return status;
            }
        }
        throw new IllegalArgumentException("Invalid order status code: " + code);
    }
}
